# My name is application image B, my artifacts are available for you:
# name: {{ application_b['name']}}
# binary path: {{ application_b['binary']}}
# suit envelope: {{ artifacts_folder ~ application_b['name'] }}.suit
# My name is radio image B, my artifacts are available for you:
# name: {{ radio_b['name']}}
# binary path: {{ radio_b['binary']}}
# suit envelope: {{ artifacts_folder ~ radio_b['name'] }}.suit

{%- set mpi_root_vendor_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_ROOT_VENDOR_NAME']|default('nordicsemi.com') %}
{%- set mpi_root_class_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_ROOT_CLASS_NAME']|default('nRF54H20_sample_root') %}
{%- set mpi_application_a_vendor_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_APP_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') %}
{%- set mpi_application_a_class_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_APP_LOCAL_1_CLASS_NAME']|default('nRF54H20_sample_app') %}
{%- set mpi_application_b_vendor_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_APP_LOCAL_2_VENDOR_NAME']|default('nordicsemi.com') %}
{%- set mpi_application_b_class_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_APP_LOCAL_2_CLASS_NAME']|default('nRF54H20_sample_app_local_2') %}
{%- set mpi_radio_a_vendor_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_RAD_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') %}
{%- set mpi_radio_a_class_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_RAD_LOCAL_1_CLASS_NAME']|default('nRF54H20_sample_rad') %}
{%- set mpi_radio_b_vendor_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_RAD_LOCAL_2_VENDOR_NAME']|default('nordicsemi.com') %}
{%- set mpi_radio_b_class_name = sysbuild['config']['SB_CONFIG_SUIT_MPI_RAD_LOCAL_2_CLASS_NAME']|default('nRF54H20_sample_rad_local_2') %}

SUIT_Envelope_Tagged:
  suit-authentication-wrapper:
    SuitDigest:
      suit-digest-algorithm-id: cose-alg-sha-256
  suit-manifest:
    suit-manifest-version: 1
{%- if APP_ROOT_SEQ_NUM is defined %}
    suit-manifest-sequence-number: {{ APP_ROOT_SEQ_NUM }}
{%- elif DEFAULT_SEQ_NUM is defined %}
    suit-manifest-sequence-number: {{ DEFAULT_SEQ_NUM }}
{%- else %}
    suit-manifest-sequence-number: 1
{%- endif %}

    suit-common:
      suit-components:

      {%- set component_index = 0 %}
      {%- set CAND_MFST_IDX = component_index %}
      - - CAND_MFST
        - 0

      {%- set BOOT_STATUS_A = 1 %}
      {%- set BOOT_STATUS_B = 2 %}
      {%- set BOOT_STATUS_A_DEGRADED = 3 %}
      {%- set BOOT_STATUS_B_DEGRADED = 4 %}
      {%- set BOOT_STATUS_A_NO_RADIO = 5 %}
      {%- set BOOT_STATUS_B_NO_RADIO = 6 %}
      {%- set BOOT_STATUS_CANNOT_BOOT = 7 %}
      {%- set component_index = component_index + 1 %}
      {%- set VAR_BOOT_STATUS_IDX = component_index %}
      - - MFST_VAR
        - 256

      {%- set component_index = component_index + 1 %}
      {%- set VAR_SET_TO_UPDATE_MIRROR_IDX = component_index %}
      - - MFST_VAR
        - 257

      {%- set SET_A = 1 %}
      {%- set SET_B = 2 %}
      # Any other value - SET_A
      {%- set component_index = component_index + 1 %}
      {%- set VAR_BOOT_PREFERENCE_IDX = component_index %}
      - - MFST_VAR
        - 0

      # SET_A or SET_B
      {%- set component_index = component_index + 1 %}
      {%- set VAR_SET_TO_UPDATE_IDX = component_index %}
      - - MFST_VAR
        - 1

      {%- set JUST_INSTALLED = 1 %}
      {%- set NOT_CONFIRMED = 2 %}
      {%- set CONFIRMED = 3 %}
      # Any other value - JUST_INSTALLED
      {%- set component_index = component_index + 1 %}
      {%- set VAR_CONFIRM_SET_A_IDX = component_index %}
      - - MFST_VAR
        - 2

      {%- set component_index = component_index + 1 %}
      {%- set VAR_CONFIRM_SET_B_IDX = component_index %}
      - - MFST_VAR
        - 3

      {%- set component_index = component_index + 1 %}
      {%- set RAD_A_INSTLD_MFST_IDX = component_index %}
      - - INSTLD_MFST
        - RFC4122_UUID:
            namespace: {{ mpi_radio_a_vendor_name }}
            name: {{ mpi_radio_a_class_name }}

      {%- set component_index = component_index + 1 %}
      {%- set RAD_B_INSTLD_MFST_IDX = component_index %}
      - - INSTLD_MFST
        - RFC4122_UUID:
            namespace: {{ mpi_radio_b_vendor_name }}
            name: {{ mpi_radio_b_class_name }}

      {%- set component_index = component_index + 1 %}
      {%- set APP_A_INSTLD_MFST_IDX = component_index %}
      - - INSTLD_MFST
        - RFC4122_UUID:
            namespace: {{ mpi_application_a_vendor_name }}
            name: {{ mpi_application_a_class_name }}

      {%- set component_index = component_index + 1 %}
      {%- set APP_B_INSTLD_MFST_IDX = component_index %}
      - - INSTLD_MFST
        - RFC4122_UUID:
            namespace: {{ mpi_application_b_vendor_name }}
            name: {{ mpi_application_b_class_name }}

    {%- set component_index = component_index + 1 %}
    {%- set TOP_INSTLD_MFST_IDX = component_index %}
      - - INSTLD_MFST
        - RFC4122_UUID:
            namespace: nordicsemi.com
            name: nRF54H20_nordic_top


      suit-shared-sequence:
      - suit-directive-set-component-index: [{{ RAD_A_INSTLD_MFST_IDX }}, {{ RAD_B_INSTLD_MFST_IDX }}, {{ APP_A_INSTLD_MFST_IDX }}, {{ APP_B_INSTLD_MFST_IDX }}]
      - suit-directive-override-parameters:
          suit-parameter-vendor-identifier:
            RFC4122_UUID: {{ mpi_root_vendor_name }}
          suit-parameter-class-identifier:
            RFC4122_UUID:
              namespace: {{ mpi_root_vendor_name }}
              name: {{ mpi_root_class_name }}
      - suit-condition-vendor-identifier: []
      - suit-condition-class-identifier: []

      suit-dependencies:
        # Key is the index of suit-components that describe the dependency manifest
        "{{ CAND_MFST_IDX }}": {}
        "{{ RAD_A_INSTLD_MFST_IDX }}": {}
        "{{ RAD_B_INSTLD_MFST_IDX }}": {}
        "{{ APP_A_INSTLD_MFST_IDX }}": {}
        "{{ APP_B_INSTLD_MFST_IDX }}": {}
        "{{ TOP_INSTLD_MFST_IDX }}": {}


    suit-validate:
    - suit-directive-set-component-index: {{ VAR_BOOT_PREFERENCE_IDX }}
    - suit-directive-try-each:
      # Checking if B is preferred and valid
      - - suit-directive-set-component-index: {{ VAR_BOOT_PREFERENCE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        # B is preferred, checking B 'confirm' status
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_CANNOT_BOOT }}
        - suit-directive-write: []
        - suit-directive-try-each:
          - - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_B_IDX }}
            - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
            - suit-directive-override-parameters:
                suit-parameter-content: {{ BOOT_STATUS_B }}
            - suit-directive-write: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B }}
        - suit-condition-check-content: []
        # B 'confirm' status allows booting, validating app and radio
        - suit-directive-set-component-index: [{{ APP_B_INSTLD_MFST_IDX }}, {{ RAD_B_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Checking if A is valid (B is not preferred or invalid)
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_CANNOT_BOOT }}
        - suit-directive-write: []
        - suit-directive-try-each:
          - - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_A_IDX }}
            - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
            - suit-directive-override-parameters:
                suit-parameter-content: {{ BOOT_STATUS_A }}
            - suit-directive-write: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A }}
        - suit-condition-check-content: []
        # A 'confirm' status allows booting, validating app and radio
        - suit-directive-set-component-index: [{{ APP_A_INSTLD_MFST_IDX }}, {{ RAD_A_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Checking if B is valid (however not preferred)
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_CANNOT_BOOT }}
        - suit-directive-write: []
        - suit-directive-try-each:
          - - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_B_IDX }}
            - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
            - suit-directive-override-parameters:
                suit-parameter-content: {{ BOOT_STATUS_B }}
            - suit-directive-write: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B }}
        - suit-condition-check-content: []
        # B 'confirm' status allows booting, validating app and radio
        - suit-directive-set-component-index: [{{ APP_B_INSTLD_MFST_IDX }}, {{ RAD_B_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Bad. There is no set fulfilling basic criteria. Try to find ANY set, where both app and radio are valid
      # Checking A
      - - suit-directive-set-component-index: [{{ APP_A_INSTLD_MFST_IDX }}, {{ RAD_A_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A_DEGRADED }}
        - suit-directive-write: []

      # Checking B
      - - suit-directive-set-component-index: [{{ APP_B_INSTLD_MFST_IDX }}, {{ RAD_B_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B_DEGRADED }}
        - suit-directive-write: []

      # Worse. Try to find valid app
      # Checking A
      - - suit-directive-set-component-index: {{ APP_A_INSTLD_MFST_IDX }}
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A_NO_RADIO }}
        - suit-directive-write: []
        # Still run validate for the radio manifest, only in order to set
        # the inactive radio partition as IPUC.
        # The sequence will fail, but due to the soft-failure parameter
        # it will not cause the whole current try-each sequence failure.
        - suit-directive-run-sequence:
          - suit-directive-set-component-index: {{ RAD_A_INSTLD_MFST_IDX }}
          - suit-directive-override-parameters:
              suit-parameter-soft-failure: True
          - suit-condition-dependency-integrity: []
          - suit-directive-process-dependency: []

      # Checking B
      - - suit-directive-set-component-index: {{ APP_B_INSTLD_MFST_IDX }}
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B_NO_RADIO }}
        - suit-directive-write: []
        # Still run validate for the radio manifest, only in order to set
        # the inactive radio partition as IPUC.
        # The sequence will fail, but due to the soft-failure parameter
        # it will not cause the whole current try-each sequence failure.
        - suit-directive-run-sequence:
          - suit-directive-set-component-index: {{ RAD_B_INSTLD_MFST_IDX }}
          - suit-directive-override-parameters:
              suit-parameter-soft-failure: True
          - suit-condition-dependency-integrity: []
          - suit-directive-process-dependency: []


    suit-invoke:
    - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
    - suit-directive-try-each:

      # Path A
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A }}
        - suit-condition-check-content: []
        # set confirm status as NOT_CONFIRMED, if FW set A was just updated
        - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_A_IDX }}
        - suit-directive-try-each:
          - - suit-directive-override-parameters:
                suit-parameter-content: {{ CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-directive-write: []
        - suit-directive-set-component-index: [{{ APP_A_INSTLD_MFST_IDX }}, {{ RAD_A_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Path B
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B }}
        - suit-condition-check-content: []
        # set confirm status as NOT_CONFIRMED, if FW set B was just updated
        - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_B_IDX }}
        - suit-directive-try-each:
          - - suit-directive-override-parameters:
                suit-parameter-content: {{ CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-condition-check-content: []
          - - suit-directive-override-parameters:
                suit-parameter-content: {{ NOT_CONFIRMED }}
            - suit-directive-write: []
        - suit-directive-set-component-index: [{{ APP_B_INSTLD_MFST_IDX }}, {{ RAD_B_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Path A, degraded
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A_DEGRADED }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: [{{ APP_A_INSTLD_MFST_IDX }}, {{ RAD_A_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Path B, degraded
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B_DEGRADED }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: [{{ APP_B_INSTLD_MFST_IDX }}, {{ RAD_B_INSTLD_MFST_IDX }}]
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Path A, just app image
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A_NO_RADIO }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ APP_A_INSTLD_MFST_IDX }}
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

      # Path B, just app image
      - - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_B_NO_RADIO }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ APP_B_INSTLD_MFST_IDX }}
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []


{%- if APP_ROOT_VERSION is defined %}
    suit-current-version: {{ APP_ROOT_VERSION }}
{%- elif DEFAULT_VERSION is defined %}
    suit-current-version: {{ DEFAULT_VERSION }}
{%- endif %}


    suit-payload-fetch:
    # setup VAR_SET_TO_UPDATE based on BOOT_STATUS
    - suit-directive-set-component-index: {{ VAR_BOOT_STATUS_IDX }}
    - suit-directive-try-each:
      - - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-directive-write: []
      - - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A_DEGRADED }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-directive-write: []
      - - suit-directive-override-parameters:
            suit-parameter-content: {{ BOOT_STATUS_A_NO_RADIO }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-directive-write: []
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-directive-write: []

    # Verify the candidate compatibility with the currently installed manifests
    - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
    - suit-directive-try-each:
      # Verify top?
      - - suit-directive-override-parameters:
            suit-parameter-uri: '#top'
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        # The top manifest is available in the envelope, verify that it can be installed.
        # Errors for this sequence from now on will cause manifest processing failure.
        - suit-directive-override-parameters:
            suit-parameter-soft-failure: False
        # Update of nordic top is only possible from the A path (using B as mirror)
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        # Verify that the application and radio images in the A slot are
        # not to old for the nordic top image being installed.
        - suit-directive-set-component-index: {{ APP_A_INSTLD_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-version:
              suit-condition-version-comparison-greater-equal: {{ MIN_COMPATIBLE_APP_VERSION_FOR_NORDIC_TOP }}
        - suit-condition-version: []
        - suit-directive-set-component-index: {{ RAD_A_INSTLD_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-version:
              suit-condition-version-comparison-greater-equal: {{ MIN_COMPATIBLE_RAD_VERSION_FOR_NORDIC_TOP }}
        - suit-condition-version: []
      # Verify application?
      - - suit-directive-set-component-index: {{ TOP_INSTLD_MFST_IDX }}
        # The top manifest is not available in the envelope - we are in the application installation path.
        # Verify the installed nordic top version is not too old to perform the update.
        - suit-directive-override-parameters:
            suit-parameter-version:
              suit-condition-version-comparison-greater-equal: {{ MIN_NORDIC_TOP_VERSION }}
        - suit-condition-version: []

    - suit-directive-try-each:
      # Install top?
      - - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: '#top'
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        # The top manifest is available in the envelope.
        # Do not verify the application and radio images, as they won't be installed.
        - suit-directive-override-parameters:
            suit-parameter-soft-failure: False
        - suit-directive-process-dependency: []
      # set A?
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ radio['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ application['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
      # Set B?
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ radio_b['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ application_b['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []


    suit-install:
    - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
    - suit-directive-try-each:
      # Install top?
      - - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: '#top'
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        # The top manifest is available in the envelope.
        # Do not install the application and radio images.
        - suit-directive-override-parameters:
            suit-parameter-soft-failure: False
        - suit-directive-process-dependency: []
      # set A?
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_A_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ JUST_INSTALLED }}
        - suit-directive-write: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ radio['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ application['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ VAR_BOOT_PREFERENCE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-directive-write: []
      # set B?
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_CONFIRM_SET_B_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ JUST_INSTALLED }}
        - suit-directive-write: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ radio_b['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ application_b['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ VAR_BOOT_PREFERENCE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-directive-write: []


    suit-candidate-verification:
    # copy SET_TO_UPDATE to SET_TO_UPDATE_MIRROR
    - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
    - suit-directive-try-each:
      - - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-directive-write: []
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-directive-write: []

    # Verify the candidate compatibility with the currently installed manifests
    - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
    - suit-directive-try-each:
      # Verify top?
      - - suit-directive-override-parameters:
            suit-parameter-uri: '#top'
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        # The top manifest is available in the envelope, verify that it can be installed.
        # Errors for this sequence from now on will cause manifest processing failure.
        - suit-directive-override-parameters:
            suit-parameter-soft-failure: False
        # Update of nordic top is only possible from the A path (using B as mirror)
        - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        # Verify that the application and radio images in the A slot are
        # not to old for the nordic top image being installed.
        - suit-directive-set-component-index: {{ APP_A_INSTLD_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-version:
              suit-condition-version-comparison-greater-equal: {{ MIN_COMPATIBLE_APP_VERSION_FOR_NORDIC_TOP }}
        - suit-condition-version: []
        - suit-directive-set-component-index: {{ RAD_A_INSTLD_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-version:
              suit-condition-version-comparison-greater-equal: {{ MIN_COMPATIBLE_RAD_VERSION_FOR_NORDIC_TOP }}
        - suit-condition-version: []
      # Verify application?
      - - suit-directive-set-component-index: {{ TOP_INSTLD_MFST_IDX }}
        # The top manifest is not available in the envelope - we are in the application installation path.
        # Verify the installed nordic top version is not too old to perform the update.
        - suit-directive-override-parameters:
            suit-parameter-version:
              suit-condition-version-comparison-greater-equal: {{ MIN_NORDIC_TOP_VERSION }}
        - suit-condition-version: []

    - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
    - suit-directive-try-each:
      # Install top?
      - - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: '#top'
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        # The top manifest is available in the envelope.
        # Do not verify the application and radio images, as they won't be installed.
        - suit-directive-override-parameters:
            suit-parameter-soft-failure: False
        - suit-directive-process-dependency: []
      # set A?
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_A }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ radio['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ application['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
      # set B?
      - - suit-directive-set-component-index: {{ VAR_SET_TO_UPDATE_MIRROR_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-content: {{ SET_B }}
        - suit-condition-check-content: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ radio_b['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []
        - suit-directive-set-component-index: {{ CAND_MFST_IDX }}
        - suit-directive-override-parameters:
            suit-parameter-uri: "#{{ application_b['name'] }}"
        - suit-directive-fetch: []
        - suit-condition-dependency-integrity: []
        - suit-directive-process-dependency: []

    suit-manifest-component-id:
    - INSTLD_MFST
    - RFC4122_UUID:
        namespace: {{ mpi_root_vendor_name }}
        name: {{ mpi_root_class_name }}

  suit-integrated-dependencies:

{%- if 'SB_CONFIG_SUIT_ENVELOPE_NORDIC_TOP_DIRECTORY' in sysbuild['config'] and sysbuild['config']['SB_CONFIG_SUIT_ENVELOPE_NORDIC_TOP_DIRECTORY'] != '' %}
    '#top': {{ artifacts_folder }}nordic_top.suit
{%- else %}
    '#{{ radio['name'] }}': {{ artifacts_folder ~ radio['name'] }}.suit
    '#{{ radio_b['name'] }}': {{ artifacts_folder ~ radio_b['name'] }}.suit
    '#{{ application['name'] }}': {{ artifacts_folder ~ application['name'] }}.suit
    '#{{ application_b['name'] }}': {{ artifacts_folder ~ application_b['name'] }}.suit
{%- endif %}
